﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Linq.Expressions;
using System.Reflection;
//using GwLib.Utility;

namespace GwLib.JqGridMvc
{
    public class JqGridColumn
    {
        public JqGridColumn() {}

        private JqGridFormatter _predefinedFormatter = new JqGridFormatter();

        public JqGridFormatter PredefinedFormatter
        {
            get { return _predefinedFormatter; }
        }

        public JqGridColumnAlignment? Alignment { get; set; }
        public string HeaderCaption { get; set; }
        public string Name { get; set; }
        public string DataSourceFieldName { get; set; }
        public int? Width { get; set; }
        public string[] CssClasses { get; set; }
        public string DateFormatString { get; set; }

        public string FormatExtensionName { get; set; }
        public string FormatFunctionName { get; set; }
        public string UnformatFunctionName { get; set; }
        public string FormatOptions { get; set; }

        public bool? IsEditable { get; set; }
        public bool? IsViewable { get; set; }
        public bool? IsFixed { get; set; }
        public bool? IsHidden { get; set; }
        public bool? IsResizable { get; set; }
        public bool? IsKey { get; set; }
        public bool? IsTitleDisplayed { get; set; }

        public bool? IsSearchable { get; set; }
        public bool? IsSortable { get; set; }
        public JqGridColumnSortType SortType { get; set; }
        public JqGridColumnEditType? EditType { get; set; }
        public string EditOptions { get; set; }
        public string SortFunctionName { get; set; }
        public string CellAttributesFunctionName { get; set; }

        public PropertyInfo MappedProperty { get; set; }

        public void MapTo<T>(Expression<Func<T, object>> expression)
        {
            MappedProperty = ReflectionUtility.GetPropertyFromExpression(expression.Body);
            Name = DataSourceFieldName = MappedProperty.Name;
        }

    }
}